<template>
  <div>
    <!-- 订货单审核-->
    <TopFilter :list="topFilterList" :cols="3" @filterChange="changeHandle" @onCollapse="collapseHandle" :labelWidth="110"></TopFilter>

    <Spin :spinning="exportLoading" tip="Loading...">
      <FilterTable
        ref="table"
        :columns="columns"
        :fetchapi="fetchApi"
        :params="fetchParams"
        :datakey="'records'"
        columnsRef="zjSignWarehousing"
        :onRowSelectChange="selectChangeHandle"
        :onColumnsChange="columns => (this.columns = columns)"
      >
        <template slot="controls" slot-scope="props">
          <multiuse-button size="small" type="primary" @click="addHandle(1)">导 出</multiuse-button>
          <multiuse-button size="small" type="primary" @click="addHandle(2)" :disabled="isShow">批量入库</multiuse-button>
        </template>
      </FilterTable>
    </Spin>

    <BaseDialog :visible.sync="iswarehouse" :title="'选择仓库'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <warehouseModel @close="warehousecloseHandler" :list="selectList" />
    </BaseDialog>
    <BaseDialog :visible.sync="isEmit" :title="'编辑'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <emitModel :rowData="formData" @close="emitcloseHandler" />
    </BaseDialog>
    <BaseDialog :visible.sync="isDetail" :title="'详情'" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <detailModel :rowData="formData" @close="detailcloseHandler" />
    </BaseDialog>
  </div>
</template>
<script>
import { getList, getDetail, postSave, getStorageList, exportStorage,exporturl } from '@/api/dealerSale/InventoryManagement/SignWarehousing/index.js';
import { dictionary } from '@/utils/dictMixin';
import warehouseModel from './warehouseModel';
import { exportExcelFile } from '@/utils';
import emitModel from './emitModel';
import detailModel from './detailModel';
export default {
  name: 'WarehouseMaintenance',
  data() {
    this.BaseTable = null;
    return {
      topFilterList: this.createdFrom(),
      columns: this.createdTable(),
      fetchParams: {},
      fetchApi: getList,
      formData: {},
      exportLoading: false,
      iswarehouse: false,
      isEmit: false,
      selectList: [],
      isShow: true,
      isDetail: false
    };
  },
  mixins: [dictionary],
  components: {
    warehouseModel,
    emitModel,
    detailModel
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  created() {},
  methods: {
    createdFrom() {
      return [
        {
          type: 'INPUT',
          label: '订单号',
          fieldName: 'doNo',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '发运单号',
          fieldName: 'transNo',
          placeholder: '请输入'
        },
        {
          type: 'INPUT',
          label: '产品名称',
          fieldName: 'productName',
          placeholder: '请输入'
        },
        {
          type: 'TEXT_AREA',
          label: 'VIN',
          fieldName: 'vin',
          placeholder: '请输入',
          maxlength: '',
          maxRows: 2
        },
        {
          type: 'RANGE_DATE',
          label: '发运日期',
          fieldName: 'beginStartDeliveryDate|endStartDeliveryDate',
          placeholder: '请选择',
          initialValue: [],
          dateType: 'exactdaterange'
        }
      ];
    },
    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 1)}>
                  编辑
                </multiuse-button>
                <el-divider direction="vertical" />
                <multiuse-button size="mini" type="text" onClick={() => this.editHandle(props.row, 2)}>
                  详情
                </multiuse-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'transStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('6003'),
          render: p => {
            return <span>{this.createDictText(p.row.transStatus, '6003')}</span>;
          }
        },
        {
          title: '订单号',
          dataIndex: 'doNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          align: 'center',
          width: 180,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发运单号',
          dataIndex: 'transNo',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '发运日期',
          dataIndex: 'startDeliveryDate',
          sorter: true,
          filter: true,
          filterType: 'date-range'
        },
        {
          title: '车系',
          dataIndex: 'seriesCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车型',
          dataIndex: 'modelCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品代码',
          dataIndex: 'productCode',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '产品名称',
          dataIndex: 'productName',
          align: 'center',
          width: 400,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '大客户项目名称',
          dataIndex: 'majorContractName',
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
    selectChangeHandle(row) {
      this.selectList = row;
      if (row.length > 0) {
        this.isShow = false;
      } else {
        this.isShow = true;
      }
    },
    // async getStorageList(){
    //   let res=await getStorageList()
    //   console.log(res,'res')
    //   this.topFilterList.map(x=>{
    //     if(x.fieldName==''){
    //       x.itemList=res.data.map(x=>({text:'',value:''}))
    //     }
    //   })
    // },
    async addHandle(type) {
      if (type == 1) {
           let json = Object.assign({}, { CODE: 'CODE_0000047' }, this.fetchParams);
      let res = await exporturl(json);
      if (res.resultCode == 200) {
        this.$router.push('/admin/auth/oem/downloadCenter');
      }

        // this.$confirm('是否将Excel表格保存至本地文件夹?', '提示', {
        //   confirmButtonText: '下载',
        //   cancelButtonText: '取消',
        //   type: 'warning'
        // })
        //   .then(() => {
        //     let json = this.fetchParams;
        //     this.exportLoading = true;

        //     exportStorage(json)
        //       .then(response => {
        //         console.log(response, 'response');
        //         exportExcelFile(response.data, '签收入库');
        //         this.exportLoading = false;
        //       })
        //       .catch(err => {
        //         console.log(err);
        //       });
        //   })
        //   .catch(() => {
        //     console.log('456');
        //     this.$message({
        //       type: 'info',
        //       message: '已取消'
        //     });
        //   });
      } else {
        this.iswarehouse = true;
      }
    },
    changeHandle(params) {
      this.fetchParams = Object.assign({}, this.fetchParams, params);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    editHandle(data, type) {
      this.formData = data;
      if (type == 1) {
        this.isEmit = true;
      } else {
        this.isDetail = true;
      }
    },
    emitcloseHandler(val) {
      this.isEmit = false;
      if (val) {
        this.fetchParams = Object.assign({}, this.fetchParams);
      }
    },
    detailcloseHandler() {
      this.isDetail = false;
    },
    warehousecloseHandler() {
      this.iswarehouse = false;
      this.fetchParams = Object.assign({}, this.fetchParams);
    }
  }
};
</script>
